<template>
  <a-modal title="密码验证" :visible="visible" @ok="onSubmit" @cancel="close">
    <a-form-model
      ref="ruleForm"
      :model="form"
      :rules="rules"
      :label-col="{ span: 6 }"
      :wrapper-col="{ span: 14 }"
    >
      <a-form-model-item label="登录密码" prop="password">
        <a-input v-model="form.password" type="password" />
      </a-form-model-item>
    </a-form-model>
  </a-modal>
</template>

<script>
export default {
  data() {
    return {
      row: null,
      visible: false,
      form: {
        password: '',
      },
      rules: {
        password: [
          {
            required: true,
            message: '请输入',
            trigger: 'blur',
          },
        ],
      },
    }
  },
  methods: {
    show(row) {
      this.row = row
      this.visible = true
    },
    close() {
      Object.assign(this.$data, this.$options.data())
    },
    onSubmit() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          this.axios.post(`/password-check`, this.form).then((res) => {
            if (res.data.code === 1) {
              this.$emit('open-coins', this.row)
              this.close()
              this.$message.success('验证成功')
            } else {
              this.$message.error(res.data.msg)
            }
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
  },
}
</script>
